//
//  BaseTableViewController.m
//  drawacartoon
//
//  Created by Ji Hu on 12-7-24.
//  Copyright (c) 2012年 爱辅导. All rights reserved.
//

#import "BaseTableViewController.h"

@interface BaseTableViewController ()

@end


@implementation BaseTableViewController

@synthesize tableView=_tableView,emptyCell=_emptyCell;
@synthesize delegate=_delegate;
@synthesize tableViewDataArray=_tableViewDataArray;
@synthesize detailViewController=_detailViewController;

-(void)dealloc{
    self.tableView=nil;
    self.emptyCell=nil;
    self.delegate=nil;
    self.tableViewDataArray=nil;
    self.detailViewController=nil;
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    if (self.emptyCell==nil) {
        NSString *emptytext = [self buildEmptyString];
        _emptyCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"emptyCell"];
        _emptyCell.textLabel.text=(emptytext==nil?@"nothing yet..":emptytext);
        _emptyCell.textLabel.textAlignment = UITextAlignmentCenter;
        _emptyCell.textLabel.textColor=[UIColor lightGrayColor];
    }
    
}

-(NSString *)buildEmptyString{
    return nil;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    int count = self.tableViewDataArray.count;
    
    if (count==0) {
        [self.tableView setAllowsSelection:NO];
        return 1;
    }
    
    [self.tableView setAllowsSelection:YES];
    
    return count;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.tableViewDataArray.count==0) {
        return;
    }
    
    id res = [self.tableViewDataArray objectAtIndex:indexPath.row];
    
    if (self.detailViewController==nil) {
        [self buildDetailViewController];
    }
    
    [self.delegate openDetailViewController:self.detailViewController withObject:res];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.tableViewDataArray.count==0) {
        return _emptyCell;
    }else {
        return [self basetableView:tableView cellForRowAtIndexPath:indexPath];
    }
}

-(UITableViewCell *)basetableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return nil;
}

-(void)loadListData:(id)params{
    
}

-(void)buildDetailViewController{
    
}

@end
